﻿using Calimbra.Runtime.Contracts;

namespace Calimbra.Runtime.Data
{
    public class Port : IPort
    {
        public Port(string fullname)
        {
            Fullname = fullname.Replace("\\", "/").Replace("*", "");
        }

        #region IPort implementation

        public string Fullname { get; private set; }

        public string Path
        {
            get
            {
                return System.IO.Path.GetDirectoryName(Fullname).Replace("\\", "/");
                // On Windows GetDirectoryName() seems to return "\" even though Fullname uses
                // just "/". An extra Replace() thus is necessary here.
            }
        }

        public string OperationName
        {
            get { return System.IO.Path.GetFileNameWithoutExtension(Fullname); }
        }

        public string Name
        {
            get { return System.IO.Path.GetExtension(Fullname).Replace(".", ""); }
        }


        public bool IsOperationPort
        {
            get { return OperationName != ""; }
        }

        #endregion

        public override string ToString()
        {
            return string.Format("Port(Fullname='{0}')", Fullname);
        }
    }
}